package com.mooke.controller;



import com.mooke.entity.Userlogin;
import com.mooke.service.impl.UserloginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Controller
public class LoginController {
    @Autowired
    private UserloginServiceImpl userloginServiceImpl;

    //登录后
    @RequestMapping("login.html")
    public  String logined(HttpServletRequest request, HttpServletResponse response, Model model)
    {
        String username = request.getParameter("username");
        String password=request.getParameter("password");
        Userlogin UserEntity=new Userlogin();
        UserEntity.setUsername(username);
        UserEntity.setPassword(password);
        Boolean Role=userloginServiceImpl.login("Userlogin.login",UserEntity);
        if(Role){
            Userlogin role =userloginServiceImpl.queryrole("Userlogin.queryrole",UserEntity);
            model.addAttribute("username", username);
            model.addAttribute("role", role.getRole());
            String r=String.valueOf(role.getRole());
            if (r.equals("1")) {
                return "redirect:/admin/showTeacher.html";
            }else if (r.equals("2")) {
                model.addAttribute("username", username);
                return "redirect:/teacher/showWages.html";
            }
        }
        return "login";
    }


    //注销
    @RequestMapping("logout.html")
    public  String logout(HttpServletRequest request, HttpServletResponse response, Model model)
    {
        return "login";
    }


}
